<template>
  <el-carousel height="66vh">
    <el-carousel-item v-for="item in carouselItems" :key="item.id">
      <img class="my_image" :src="item.imgUrl" :alt="item.title" />
    </el-carousel-item>
  </el-carousel>

  <div class="home-content-container">
    <div class="home-content-title">重要通知</div>
    <div class="home-content">
      <img
        src="@/assets/report.png"
        alt="welcome"
        style="margin-left: 10px"
        height="120px"
      />
      <div style="display: flex; flex-direction: column">
        <div
          class="my_button_1"
          style="margin-top: -40px"
          @click="navigateTo('/test/analysis')"
        >
          置顶
        </div>
        <span
          @click="navigateTo('/test/echarts/analysis')"
          style="margin-left: 60px; margin-top: -22px; cursor: pointer"
          >查看详情</span
        >
      </div>
      <div style="margin-top: 65px; margin-left: -115px; cursor: default">
        <span>
          欢迎用户: <span class="username">{{ name }}</span>
        </span>
        <span style="display: block" v-if="showRank">
          您在班级的排名为：第<span class="rank">{{ rank }}</span
          >名
        </span>
      </div>
    </div>
    <div
      style="
        width: 95%;
        height: 1px;
        background-color: rgb(237, 226, 226);
        margin: 0 auto;
      "
    ></div>
    <div class="home-content">
      <img
        src="@/assets/test.png"
        alt="welcome"
        style="margin-left: 10px"
        height="120px"
      />
      <div style="display: flex; flex-direction: column">
        <div
          @click="navigateTo('/test/index')"
          class="my_button_1"
          style="margin-top: -40px"
        >
          置顶
        </div>
        <span
          @click="navigateTo('/test/index')"
          style="margin-left: 60px; margin-top: -22px; cursor: pointer"
          >查看试卷</span
        >
      </div>
      <div style="margin-top: 65px; margin-left: -115px; cursor: default">
        <span>
          您还有<span style="color: red">{{ store.getters.paperCount }}</span
          >份试卷未做
        </span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from "vue";

import { useStore } from "vuex";
import gradeApi from "@/api/grade";
import router from "@/router";

const store = useStore();
const name = computed(() => {
  return store.getters.name;
});
const showRank = ref(false);
const rank = ref(0);

const carouselItems = ref([
  {
    id: 1,
    title: "轮播图1",
    imgUrl: new URL("@/assets/banner1.jpg", import.meta.url).href,
  },
  {
    id: 2,
    title: "轮播图2",
    imgUrl: new URL("@/assets/banner2.jpg", import.meta.url).href,
  },
  {
    id: 3,
    title: "轮播图3",
    imgUrl: new URL("@/assets/banner3.jpg", import.meta.url).href,
  },
]);

const navigateTo = (path) => {
  router.push(path);
};

const getRank = async function () {
  const res = await gradeApi.getUserRank();
  rank.value = res.data;
  if (rank.value > 0) {
    showRank.value = true;
  }
};

onMounted(() => {
  if (store.getters.roles.includes("student")) {
    getRank();
  }
});
</script>

<style scoped>
/* 设置走马灯容器的宽度 */
.el-carousel {
  width: 100%; /* 或者设置具体像素值，比如 width: 1000px */
}

/* 设置走马灯图片的样式 */
.my_image {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 保持图片比例并填充容器 */
}

.home-content-container {
  border: 1px solid rgb(237, 226, 226);
  border-radius: 3px;
  margin: 0 auto;
  margin-top: 20px;
  width: 95%;
}

.home-content {
  flex-direction: row;
  display: flex;
  justify-content: left;
  align-items: center;
}

.home-content-title {
  font-size: 18px;
  display: flex;
  background-color: rgb(217, 162, 135);
  justify-content: center;
  align-items: center;
  font-family: "微软雅黑";
  width: 140px;
  height: 40px;
  color: white;
  border-radius: 5px;
  margin-left: -20px;
  margin-top: 10px;
}

.table-content {
  width: 100%;
  border: 1px solid rgb(237, 226, 226);
  border-radius: 5px;
  margin: 0 auto;
  margin-top: 20px;
}

.username {
  color: rgb(26, 189, 26);
}

.rank {
  color: rgb(255, 0, 0);
}

.my_button_1 {
  width: 50px;
  height: 20px;
  border-radius: 5px;
  color: white;
  text-align: center;
  line-height: 20px;
  font-size: 12px;
  cursor: pointer;
  background-color: rgb(64, 158, 255);
}

.my_button_1:hover {
  background-color: rgb(102, 178, 255);
}
</style>
